package LanQiaoDemo;

import java.util.Scanner;

public class Demo3 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        while (scan.hasNext()) {
            long leftNum = scan.nextLong();//左区间
            long rightNum = scan.nextLong();//右区间
            long sum = 0;
            for (long i = leftNum; i <= rightNum; i++) {
                if (i % 6 == 0) {
                    continue;
                }
                if (!method(i)) {
                    continue;
                }
                sum += i;
            }
            System.out.println(sum);
        }
        scan.close();
    }

    private static boolean method(long num) {
        long sum = 0;
        while (num != 0) {
            long a = num % 10;
            if (a == 6) {
                return false;
            }
            sum += a;
            num /= 10;
        }
        return !(sum % 6 == 0);
    }

//    private static boolean method1(long num) {//判断某一位是不是6
//        while (num != 0) {
//            if (num % 10 == 6) {
//                return true;
//            }
//            num = num / 10;
//        }
//        return false;
//    }
//
//    private static boolean method2(long num) {//判断位数和是不是6的倍数
//        long sum = 0;
//        while (num != 0) {
//            sum += num % 10;
//            num /= 10;
//        }
//        return sum % 6 == 0;
//    }
}
